package com.h.chatroom.common.advice;

import com.h.chatroom.common.exception.ChatroomException;
import com.h.chatroom.pojo.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ResponseBody
@ControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler
    public Result exceptionHandler(Exception exception) {
        log.error("发生异常 exception: {}" + exception.getMessage());
        return Result.fail(exception.getMessage());
    }

    @ExceptionHandler
    public Result exceptionHandler(ChatroomException exception) {
        log.error("发生异常 exception: {}" + exception.getErrMsg());
        return Result.fail(exception.getErrMsg());
    }
}
